package com.myapp.api.mapper;

import com.myapp.api.entity.Course;
import org.apache.ibatis.annotations.*;
import org.apache.ibatis.type.JdbcType;

import java.util.List;

public interface CourseMapper {
    @Delete({
        "delete from course",
        "where id = #{id,jdbcType=INTEGER}"
    })
    int deleteByPrimaryKey(Integer id);

    @Insert({
        "insert into course (id, Cid, ",
        "Tid, Cname, Credit, ",
        "Count, CreateTime, ",
        "UpdateTime)",
            "values (#{id,jdbcType=INTEGER}, #{cid,jdbcType=VARCHAR}, ",
            "#{tid,jdbcType=VARCHAR}, #{cname,jdbcType=VARCHAR}, #{credit,jdbcType=DOUBLE}, ",
        "#{count,jdbcType=INTEGER}, #{createtime,jdbcType=TIMESTAMP}, ",
        "#{updatetime,jdbcType=TIMESTAMP})"
    })
    int insert(Course record);

    @InsertProvider(type=CourseSqlProvider.class, method="insertSelective")
    int insertSelective(Course record);

    @Select({
        "select",
        "id, Cid, Tid, Cname, Credit, Count, CreateTime, UpdateTime",
        "from course",
            "where id = #{id,jdbcType=INTEGER}"
    })
    @Results({
        @Result(column="id", property="id", jdbcType=JdbcType.INTEGER, id=true),
            @Result(column = "Cid", property = "cid", jdbcType = JdbcType.VARCHAR),
            @Result(column = "Tid", property = "tid", jdbcType = JdbcType.VARCHAR),
        @Result(column="Cname", property="cname", jdbcType=JdbcType.VARCHAR),
        @Result(column="Credit", property="credit", jdbcType=JdbcType.DOUBLE),
        @Result(column="Count", property="count", jdbcType=JdbcType.INTEGER),
        @Result(column="CreateTime", property="createtime", jdbcType=JdbcType.TIMESTAMP),
        @Result(column="UpdateTime", property="updatetime", jdbcType=JdbcType.TIMESTAMP)
    })
    Course selectByPrimaryKey(Integer id);

    @UpdateProvider(type=CourseSqlProvider.class, method="updateByPrimaryKeySelective")
    int updateByPrimaryKeySelective(Course record);

    @Update({
        "update course",
            "set Cid = #{cid,jdbcType=VARCHAR},",
            "Tid = #{tid,jdbcType=VARCHAR},",
          "Cname = #{cname,jdbcType=VARCHAR},",
          "Credit = #{credit,jdbcType=DOUBLE},",
          "Count = #{count,jdbcType=INTEGER},",
          "CreateTime = #{createtime,jdbcType=TIMESTAMP},",
          "UpdateTime = #{updatetime,jdbcType=TIMESTAMP}",
        "where id = #{id,jdbcType=INTEGER}"
    })
    int updateByPrimaryKey(Course record);

    @Select({
            "select",
            "id, Cid, Tid, Cname, Credit, Count, CreateTime, UpdateTime",
            "from course"
    })
    @Results({
            @Result(column="id", property="id", jdbcType=JdbcType.INTEGER, id=true),
            @Result(column = "Cid", property = "cid", jdbcType = JdbcType.VARCHAR),
            @Result(column = "Tid", property = "tid", jdbcType = JdbcType.VARCHAR),
            @Result(column="Cname", property="cname", jdbcType=JdbcType.VARCHAR),
            @Result(column="Credit", property="credit", jdbcType=JdbcType.DOUBLE),
            @Result(column="Count", property="count", jdbcType=JdbcType.INTEGER),
            @Result(column="CreateTime", property="createtime", jdbcType=JdbcType.TIMESTAMP),
            @Result(column="UpdateTime", property="updatetime", jdbcType=JdbcType.TIMESTAMP)
    })
    List<Course> getCourses();

    @Select({
            "select",
            "id, Cid, Tid, Cname, Credit, Count, CreateTime, UpdateTime",
            "from course",
            "where Cid = #{cid,jdbcType=VARCHAR}"
    })
    @Results({
            @Result(column="id", property="id", jdbcType=JdbcType.INTEGER, id=true),
            @Result(column = "Cid", property = "cid", jdbcType = JdbcType.VARCHAR),
            @Result(column = "Tid", property = "tid", jdbcType = JdbcType.VARCHAR),
            @Result(column="Cname", property="cname", jdbcType=JdbcType.VARCHAR),
            @Result(column="Credit", property="credit", jdbcType=JdbcType.DOUBLE),
            @Result(column="Count", property="count", jdbcType=JdbcType.INTEGER),
            @Result(column="CreateTime", property="createtime", jdbcType=JdbcType.TIMESTAMP),
            @Result(column="UpdateTime", property="updatetime", jdbcType=JdbcType.TIMESTAMP)
    })
    Course getCourseByCid(String cid);

    @Select({
            "select",
            "id, Cid, Tid, Cname, Credit, Count, CreateTime, UpdateTime",
            "from course",
            "where Cname like concat('%',#{cname,jdbcType=VARCHAR},'%')"
    })
    @Results({
            @Result(column="id", property="id", jdbcType=JdbcType.INTEGER, id=true),
            @Result(column = "Cid", property = "cid", jdbcType = JdbcType.VARCHAR),
            @Result(column = "Tid", property = "tid", jdbcType = JdbcType.VARCHAR),
            @Result(column="Cname", property="cname", jdbcType=JdbcType.VARCHAR),
            @Result(column="Credit", property="credit", jdbcType=JdbcType.DOUBLE),
            @Result(column="Count", property="count", jdbcType=JdbcType.INTEGER),
            @Result(column="CreateTime", property="createtime", jdbcType=JdbcType.TIMESTAMP),
            @Result(column="UpdateTime", property="updatetime", jdbcType=JdbcType.TIMESTAMP)
    })
    List<Course> getCourseByCname(String cname);

    @Select({
            "select count(*)",
            "id, Cid, Tid, Cname, Credit, Count, CreateTime, UpdateTime",
            "from course",
            "where Cid = #{cid,jdbcType=VARCHAR}"
    })
    Integer getCourseByOneCid(String cid);
}